package com.stella.ieproductivitybackend.controller;

import com.stella.ieproductivitybackend.entity.*;
import com.stella.ieproductivitybackend.entity.Progress;
import com.stella.ieproductivitybackend.service.HomeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 首页控制层
 */
@RestController
@RequestMapping("/home")
public class HomeController {
    @Autowired
    private HomeService homeService;

    /**
     * 工厂列表
     */
    @PostMapping("/getFactoryList")
    public List<Factory> getFactoryList() {
        return homeService.getFactoryList();
    }

    /**
     * 品牌列表
     */
    @PostMapping("/getBrandList")
    public List<Brand> getBrandList() {
        return homeService.getBrandList();
    }

    /**
     * 品牌类型
     */
    @PostMapping("/getBrandType")
    public List<Brand> getBrandType() {
        return homeService.getBrandType();
    }

    /**
     * 型体数量
     */
    @PostMapping("/getModelCount")
    public Integer getModelCount() {
        return homeService.getModelCount();
    }

    /**
     * 型体列表
     */
    @PostMapping("/getModelList")
    public List<Model> getModelList() {
        return homeService.getModelList();
    }

    /**
     * 搜索型体
     */
    @PostMapping("/searchModel")
    public List<Model> searchModel(@RequestBody Map<String, Object> params) {
        String model = params.get("model") != null ? params.get("model").toString() : "";
        return homeService.searchModel(model);
    }

    /**
     * 员工总数
     */
    @PostMapping("/getEmployeeCount")
    public int getEmployeeCount() {
        return homeService.getEmployeeCount();
    }

    /**
     * 直间人工力其他数据
     */
    @PostMapping("/getEmployeeOther")
    public Map<String, Object> getEmployeeOther() {
        return homeService.getEmployeeOther();
    }

    /**
     * 直间人工力详情
     */
    @PostMapping("/getEmployeeDetail")
    public List<Employee> getEmployeeDetail(@RequestBody Map<String, Object> params) {
        String year = params.get("year") != null ? params.get("year").toString() : "";
        String month = params.get("month") != null ? params.get("month").toString() : "";
        String factory = params.get("factory") != null ? params.get("factory").toString() : "";
        return homeService.getEmployeeDetail(year, month, factory);
    }

    /**
     * 纯粹达成率图表
     */
    @PostMapping("/getPureChart")
    public Map<String, Object> getPureChart() {
        return homeService.getPureChart();
    }

    /**
     * 纯粹达成率详情
     */
    @PostMapping("/getPureDetail")
    public Map<String, List<Pure>> getPureDetail() {
        return homeService.getPureDetail();
    }

    /**
     * 直间达成率图表
     */
    @PostMapping("/getDirectChart")
    public Map<String, Object> getDirectChart() {
        return homeService.getDirectChart();
    }

    /**
     * 直间达成率详情
     */
    @PostMapping("/getDirectDetail")
    public Map<String, List<Direct>> getDirectDetail() {
        return homeService.getDirectDetail();
    }

    /**
     * 入库标准秒值图表
     */
    @PostMapping("/getWarehousingChart")
    public Map<String, Object> getWarehousingChart() {
        return homeService.getWarehousingChart();
    }

    /**
     * 入库标准秒值其他数据
     */
    @PostMapping("/getWarehousingOther")
    public Map<String, Object> getWarehousingOther() {
        return homeService.getWarehousingOther();
    }

    /**
     * 入库标准秒值详情
     */
    @PostMapping("/getWarehousingDetail")
    public List<Warehousing> getWarehousingDetail(@RequestBody Map<String, Object> params) {
        String year = params.get("year") != null ? params.get("year").toString() : "";
        String month = params.get("month") != null ? params.get("month").toString() : "";
        return homeService.getWarehousingDetail(year, month);
    }

    /**
     * 入库标准秒值对比
     */
    @PostMapping("/getWarehousingCompare")
    public List<Warehousing> getWarehousingCompare(@RequestBody Map<String, Object> params) {
        String factory1 = params.get("factory1") != null ? params.get("factory1").toString() : "";
        String year1 = params.get("year1") != null ? params.get("year1").toString() : "";
        String month1 = params.get("month1") != null ? params.get("month1").toString() : "";
        String factory2 = params.get("factory2") != null ? params.get("factory2").toString() : "";
        String year2 = params.get("year2") != null ? params.get("year2").toString() : "";
        String month2 = params.get("month2") != null ? params.get("month2").toString() : "";
        return homeService.getWarehousingCompare(factory1, year1, month1, factory2, year2, month2);
    }

    /**
     * 当月成型完工数量图表
     */
    @PostMapping("/getCompletedChart")
    public CompletedChart getCompletedChart() {
        return homeService.getCompletedChart();
    }

    /**
     * 成型完工数量其它
     */
    @PostMapping("/getCompletedOther")
    public Map<String, Object> getCompletedOther() {
        return homeService.getCompletedOther();
    }

    /**
     * 成型完工数量详情
     */
    @PostMapping("/getCompletedDetail")
    public List<Completed> getCompletedDetail(@RequestBody Map<String, Object> params) {
        String year = params.get("year") != null ? params.get("year").toString() : "";
        String month = params.get("month") != null ? params.get("month").toString() : "";
        return homeService.getCompletedDetail(year, month);
    }

    /**
     * 当月新旧型体占比图表
     */
    @PostMapping("/getProportionChart")
    public ProportionChart getProportionChart() {
        return homeService.getProportionChart();
    }

    /**
     * 新旧型体占比其它
     */
    @PostMapping("/getProportionOther")
    public Map<String, Object> getProportionOther() {
        return homeService.getProportionOther();
    }

    /**
     * 新旧型体占比详情
     */
    @PostMapping("/getProportionDetail")
    public List<Proportion> getProportionDetail(@RequestBody Map<String, Object> params) {
        String year = params.get("year") != null ? params.get("year").toString() : "";
        String month = params.get("month") != null ? params.get("month").toString() : "";
        return homeService.getProportionDetail(year, month);
    }

    /**
     * PPH 图表
     */
    @PostMapping("/getPPHChart")
    public Map<String, Object> getPPHChart() {
        return homeService.getPPHChart();
    }

    /**
     * PPH 详情
     */
    @PostMapping("/getPPHDetail")
    public Map<String, List<PPH>> getPPHDetail() {
        return homeService.getPPHDetail();
    }

    /**
     * 与核算进度达成图表
     */
    @PostMapping("/getProgressChart")
    public Map<String, Object> getProgressChart() {
        return homeService.getProgressChart();
    }

    /**
     * 与核算进度达成其它
     */
    @PostMapping("/getProgressOther")
    public Map<String, Object> getProgressOther() {
        return homeService.getProgressOther();
    }

    /**
     * 与核算进度达成详情
     */
    @PostMapping("/getProgressDetail")
    public List<Progress> getProgressDetail(@RequestBody Map<String, Object> params) {
        String year = params.get("year") != null ? params.get("year").toString() : "";
        String month = params.get("month") != null ? params.get("month").toString() : "";
        return homeService.getProgressDetail(year, month);
    }
}
